<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns date formatted according to given format</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="datetime.diff.html">DateTime::diff</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="datetime.getoffset.html">DateTime::getOffset</a></div>
 <div class="up"><a href="class.datetimeinterface.html">DateTimeInterface</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="datetime.format" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTime::format</h1>
  <h1 class="refname">DateTimeImmutable::format</h1>
  <h1 class="refname">DateTimeInterface::format</h1>
  <h1 class="refname">date_format</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0)</p><p class="refpurpose"><span class="refname">DateTime::format</span> -- <span class="refname">DateTimeImmutable::format</span> -- <span class="refname">DateTimeInterface::format</span> -- <span class="refname">date_format</span> &mdash; <span class="dc-title">Returns date formatted according to given format</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-datetime.format-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><strong>DateTime::format</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span>
   )</div>

  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><strong>DateTimeImmutable::format</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span>
   )</div>

  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><strong>DateTimeInterface::format</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span>
   )</div>

  <p class="para rdfs-comment">过程化风格</p>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><a href="function.date-format.html" class="methodname">date_format</a></span>
    ( <span class="methodparam"><span class="type"><a href="class.datetimeinterface.html" class="type DateTimeInterface">DateTimeInterface</a></span> <code class="parameter">$object</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span>
   )</div>

  <p class="para rdfs-comment">
   Returns date formatted according to given format.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-datetime.format-parameters">
  <h3 class="title">参数</h3>
  <dl>

   <dt>
<em><code class="parameter">object</code></em></dt>

<dd>
<p class="para">仅为过程化风格：由 <span class="function"><a href="function.date-create.html" class="function">date_create()</a></span> 返回的 <a href="class.datetime.html" class="classname">DateTime</a> 类型的对象。</p></dd>

   
    <dt>
<em><code class="parameter">format</code></em></dt>

    <dd>

     <p class="para">
      Format accepted by <span class="function"><a href="function.date.html" class="function">date()</a></span>.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-datetime.format-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the formatted date string on success 或者在失败时返回 <strong><code>FALSE</code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-datetime.format-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2209">
   <p><strong>Example #1 <span class="function"><strong>DateTime::format()</strong></span> example</strong></p>
   <div class="example-contents"><p>面向对象风格</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$date&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">'2000-01-01'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d&nbsp;H:i:s'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>过程化风格</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$date&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date_create</span><span style="color: #007700">(</span><span style="color: #DD0000">'2000-01-01'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">date_format</span><span style="color: #007700">(</span><span style="color: #0000BB">$date</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Y-m-d&nbsp;H:i:s'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
2000-01-01 00:00:00
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-datetime.format-notes">
  <h3 class="title">注释</h3>
  <p class="para">
   This method does not use locales. All output is in English.
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-datetime.format-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="function.date.html" class="function" rel="rdfs-seeAlso">date()</a> - 格式化一个本地时间／日期</span></li>
  </ul>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="datetime.diff.html">DateTime::diff</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="datetime.getoffset.html">DateTime::getOffset</a></div>
 <div class="up"><a href="class.datetimeinterface.html">DateTimeInterface</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
